package com.bitdf.txing.group.feign.impl.chat;

import com.bitdf.txing.chat.feign.ChatSearchFeignService;
import com.bitdf.txing.common.enume.TxCodeEnume;
import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.search.service.GroupSearchService;
import com.bitdf.txing.search.service.GroupUpdateService;
import com.bitdf.txing.search.to.GroupInfoTo;
import com.bitdf.txing.search.to.GroupOutlineTo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * @author Lizhiwei
 * @date 2023/9/6 20:38:18
 * 注释：
 */
@Service
@Slf4j
@ConditionalOnProperty(value = "tx.deploy.mode", havingValue = "standalone")
public class ChatSearchFeignServiceImpl implements ChatSearchFeignService {
    @Autowired
    GroupSearchService groupSearchService;
    @Autowired
    GroupUpdateService groupUpdateService;

    @Override
    public R isGroupId(Long groupId) {
        Boolean b = null;
        try {
            b = groupSearchService.isGroupId(groupId);
        } catch (IOException e) {
            log.info("{}", e);
        }
        return b ? R.ok() : R.error();
    }

    @Override
    public R getGroupSimpleByGroupIds(Set<Long> groupIds) throws IOException {
        List<GroupOutlineTo> list= groupSearchService.getGroupSimpleByGroupIds(groupIds);
        return R.ok().put("data", list);
    }

    @Override
    public R groupInfoIncreOrDcre(Long groupId, Integer opsValue, String target) throws IOException {
        Boolean b = groupUpdateService.increOrDcre(groupId, opsValue, target);
        return b ? R.ok() : R.error(TxCodeEnume.COMMON_OPS_FAILURE_EXCEPTION.getCode(), TxCodeEnume.COMMON_OPS_FAILURE_EXCEPTION.getMsg());
    }

    @Override
    public R getGroupInfoById(Long id) throws IOException {
        GroupInfoTo groupInfoTo=groupSearchService.getGroupById(id);
        return R.ok().put("data", groupInfoTo);
    }
}
